#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;

int n, c, a[N];

int bs(int t)
{
	int l = 1, r = n;
	while(l < r)
	{
		int mid = l + r >> 1;
		if(a[mid] >= t) r = mid;
		else l = mid + 1;
	}
	if(a[l] < t) return 0;
	int b = l;
	l = 1, r = n;
	while(l < r)
	{
		int mid = l + r + 1>> 1;
		if(a[mid] <= t) l = mid;
		else r = mid - 1;
	}
	if(a[l] > t) return 0;
	return l - b + 1;
}

int main()
{
	cin >> n >> c;
	for(int i = 1;i <= n;i ++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	long long ans = 0;
	for(int i = 1;i <= n;i ++)
	{
		int t = a[i] + c;
		ans += bs(t);
	}
	cout << ans << endl;
	return 0;
}